<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>内容管理</title>
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<link href="/res/third/powerFloat/css/powerFloat.css" rel="stylesheet" type="text/css" />
<script src="/res/third/powerFloat/js/mini/jquery-powerFloat-min.js" type="text/javascript"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/res/third/ueditor/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
		.lpdiv{display: inline-block;float: left;margin-left: 220px;margin-top: 15px;width: 100%;}
		.showimgs{display: inline-block;}
		.delimgas{display:inline-block;margin-left:50px;cursor:pointer;}
</style>
<script type="text/javascript">
var editor;
$(function() {
	var option = {
			theme : "default",
			lang : "zh-cn",
			initialFrameWidth : 800,
			initialFrameHeight : 250,
			autoHeightEnabled : false,
			pasteplain : true,//默认纯文本格式粘贴,
			elementPathEnabled : false,
			focus : false,//初始化时不让编辑器获取焦点
			toolbars : [ [ 'fullscreen', 'source', 'undo', 'redo', 'bold',
					'indent', 'italic', 'underline', 'strikethrough',
					'justifyleft', 'justifyright', 'justifycenter',
					'justifyjustify', 'rowspacingtop', 'rowspacingbottom',
					'lineheight', 'removeformat', '|', 'fontfamily',
					'fontsize', 'forecolor', 'backcolor', 'insertorderedlist',
					'insertunorderedlist', 'insertimage', 'emotion',
					'inserttable', 'mergeright', 'mergedown', 'deleterow',
					'deletecol', 'splittorows', 'splittocols', 'splittocells',
					'deletecaption', 'mergecells', 'deletetable' ] ]
		};
		editor = UE.getEditor('container', option);
})

var exceldialog=null;
function uploaddialog(){
	//var param ={id:newproid};
	exceldialog = art.dialog.uploadFile("上传礼品",{callback:"uploadcallback",userpath:"admin",extensions:"gif,jpg,png,jepg"});
}

function uploadcallback(response){
	//alert(response.url);
	//alert(params.id);
	exceldialog.close();
	$("#mainlpdiv").append("<div class='lpdiv'>"
			+"<a target='_blank' class='showimgs' href='"+response.url+"'>"+response.url+"</a>"
			+"<a onclick='delimgs(this)' class='delimgas'>删除</a></div>");
}

function delimgs(node){
	$(node).parents(".lpdiv").remove();
}

var giftInfoId='${gift.id!}'
function subForm(){
	var giftInfo={};
	var giftName=$("#giftName").val().trim();
	if(giftName==""){
		alert("礼物名称不能为空");
		return false;
	}else{
		giftInfo.giftName=giftName;
	}
	
	var seq=$("#seq").val().trim();
	if(seq==""){
		alert("排序号不能为空");
		return false;
	}else{
		giftInfo.seq=seq;
	}
	
	var stockAmount=$("#stockAmount").val().trim();
	if(stockAmount==""){
		alert("礼品库存不能为空");
		return false;
	}else{
		giftInfo.stockAmount=stockAmount;
	}
	
	var giftType;
	$("[name='giftType']").each(function(){
		if($(this).is(":checked")){
			giftType=$(this).val();
		}
	})
	giftInfo.giftType=giftType;
	
	var t=/^([1-9]\d*|0)(\.\d{1,2})?$/;
	var giftPrice=$("#giftPrice").val().trim();
	if(!t.test(giftPrice)){
		alert("礼品价值格式不对")
		return false;
	}else{
		giftInfo.giftPrice=giftPrice;
	}
	
	var integralNum=$("#integralNum").val().trim();
	if(integralNum==""){
		alert("兑换积分不能为空");
		return false;
	}else{
		giftInfo.integralNum=integralNum;
	}
	
	var imgUrlCount=$(".showimgs").length;
	if(imgUrlCount==0){
		alert("请上传至少一张图片");
		return false;
	}else{
		var imgUrl="";
		$(".showimgs").each(function(index){
			if(index!=(imgUrlCount-1)){
				imgUrl+=$(this).attr("href")+";";
			}else{
				imgUrl+=$(this).attr("href");
			}
		})
		giftInfo.imgUrl=imgUrl;
	}
	
	var supportCompany=$("#supportCompany").val().trim();
	if(supportCompany==""){
		giftInfo.supportCompany="安装通";
	}else{
		giftInfo.supportCompany=supportCompany;
	}
	
	var giftDesc = editor.getContent().trim();
	if(giftDesc==""){
		alert("请输入礼品详情");
		return false;
	}else{
		giftInfo.giftDesc=giftDesc;
	}
	
	if(giftInfoId!=""){
		giftInfo.id=giftInfoId;
	}
	art.dialog.post({
		  
		type : "post",
		dataType : "json",
		url : "/gift/subGift.do",
		contentType : "application/json; charset=utf-8",
        data:JSON.stringify(giftInfo),
		success : function(data) {
			 if(data.success){
				 top.closeTempTab(true);
			 }else{
				 alert(data.msg);
			 }
		}
 
		},"数据正在提交.... ");
}
</script>
</head>
<body>
<!-- 新建 -->
	   <div class="panel panel-info" style="height: 100%;overflow-y:scroll;">
	        <div class="panel-heading">
	          <h3 class="panel-title">礼品管理</h3>
	        </div>
        <div class="panel-body" style="overflow: hidden;border-bottom: none;">
			<form class="form-horizontal" role="form"   id="mainForm">
			  <div class="form-group" style="margin-top:15px;">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品名称</label>
			    <div class="col-sm-5">
			      <input type="text" class="form-control" id="giftName" placeholder="请输入礼品名称" name="giftName" required="required" value="${gift.giftName!}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>排序号</label>
			    <div class="col-sm-5">
			      <input type="number"  class="form-control" id="seq" placeholder="请输入排序号" name="seq" required="required" value="${gift.seq!}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品库存</label>
			    <div class="col-sm-5">
			      <input type="number" class="form-control" id="stockAmount" placeholder="请输入礼品库存" name="stockAmount" required="required" value="${gift.stockAmount!}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label">礼品类别</label>
			    <div class="col-sm-5">
			      <input type="radio" id="giftType_sw" name="giftType" [#if gift.giftType?? && gift.giftType==2]checked="checked"[/#if] [#if !gift.giftType??]checked="checked"[/#if] value="2" onclick="initControl()">实物
			      <input type="radio" id="giftType_xn" name="giftType" [#if gift.giftType?? && gift.giftType==1]checked="checked"[/#if] value="1" onclick="initControl()">虚拟
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品价值</label>
			    <div class="col-sm-5">
			      <input type="text" class="form-control" id="giftPrice" placeholder="请输入礼品价值" name="giftPrice" required="required" value="${gift.giftPrice!}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>兑换积分</label>
			    <div class="col-sm-5">
			      <input type="number" class="form-control" id="integralNum" placeholder="请输入兑换积分" name="integralNum" required="required" value="${gift.integralNum!}">
			    </div>
			  </div>
			  <div class="form-group" id="mainlpdiv">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品图片</label>
			    <div class="col-sm-8">
					<button onclick="uploaddialog()" type="button" class="btn btn-default">礼品图片</button>
				</div>
				[#if gift?? && gift.imgUrlArr??]
					[#list gift.imgUrlArr as url]
						  <div class="lpdiv">
								<a target="_blank" class="showimgs" href="${url!}">${url!}</a>
								<a onclick="delimgs(this)" class="delimgas">删除</a>
						  </div>
					[/#list]
				[/#if]
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>提供方</label>
			    <div class="col-sm-5">
			      <input type="text" class="form-control" id="supportCompany" placeholder="请输入提供方,不写默认安装通" name="supportCompany" required="required" value="${gift.supportCompany!}">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>礼品详情</label>
			    <div class="col-sm-5">
			        <script id="container" name="giftDesc" type="text/plain">${gift.giftDesc!}</script>
			    </div>
			  </div>
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <!--  
			      <button type="button" class="btn btn-info" onclick="validateForm();">提交</button>
			      -->
			      <button type="button" class="btn btn-info" onclick="subForm();">提交</button>
			    </div>
			  </div>
			</form>
        </div>
      </div>
</body>
</html>

